package community.hospital.aspect;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.interceptor.CustomizableTraceInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @Author：ydj
 * @Date：2023/2/6 22:06
 */
//@Component
@Aspect
public class TraceAop {

    @Pointcut("execution(* community.hospital.controller..*.*(..))")
    public void pointcut() {

    }

    @Bean
    public Advisor traceAdvisor() {
        CustomizableTraceInterceptor interceptor = new CustomizableTraceInterceptor();
        interceptor.setEnterMessage("访问:$[targetClassName]:$[methodName]([arguments])");
        interceptor.setExitMessage("离开:$[methodName]():$[returnValue]");
        interceptor.setUseDynamicLogger(true);
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression("community.hospital.aspect.TraceAop.pointcut()");
        return new DefaultPointcutAdvisor(pointcut,interceptor);
    }
}
